<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
  <div class="body-content">
    <form method="post"  class="form-x" action="/workview1/updataStudent" >
	
	<div class="student-list" id="student-list" name="student-list">
	
		
	</div>



      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="button" id="button bg-main icon-check-square-o" onclick="check11()" > 提交</button>
        </div>
      </div>
	  
    </form>
  </div>
</div>

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
    $(function() {
        var studentsno = localStorage.getItem("studentsno");
        $.ajax({
            type: "POST",
            url: "/workview1/studentSupList1",
            data: ({
                sno: studentsno
            }),
            success: function (data) {
                console.log(data);
                if (data.status == 401) {
                    alert("熔断开启，系统异常");
                    window.location.href = "login.html";
                    return;
                }
                if (data.status == 200) {
                    var lists = data.data;
                    console.log(data);
                    for (var i = 0; i < lists.length; i++) {
                        var html = "";
                        html += ` <div class="form-group">
        <div class="label">
          <label>输入学号：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="${lists[i].sno}" readonly="readonly" name="sno" id="sno" data-validate="required:请输入学号长度11位" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>

      <div class="form-group">
        <div class="label">
          <label>请输入密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" value="${lists[i].password}" name="password" id="password" data-validate="required:请输入密码" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>

		<div class="form-group">
		  <div class="label">
		    <label>再次输入密码：</label>
		  </div>
		  <div class="field">
		    <input type="password" class="input w50" value="${lists[i].password}" name="password1" id="password1" data-validate="required:请输入密码" />
		    <span style="margin-left: 10px; color: red;">*</span>
		    <div class="tips"> </div>
		  </div>
		</div>

      <div class="form-group">
        <div class="label">
          <label>添加姓名：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="${lists[i].name}" name="name" id="name" data-validate="required:请输入添加人的姓名" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>

	  <div class="form-group">
	    <div class="label">
	      <label>添加学院：</label>
	    </div>
	    <div class="field">
	      <input type="text" class="input w50" value="${lists[i].college_name}" name="college_name" id="college_name" data-validate="required:请输入添加人的学院"/>
			<span style="margin-left: 10px; color: red;">*</span>
	      <div class="tips"> </div>
	    </div>
	  </div>

	  <div class="form-group">
		   <div class="label">
		     <label>添加年级：</label>
		   </div>
		   <div class="field">
		     <input type="text" class="input w50" value="${lists[i].grade}" name="grade" id="grade" data-validate="required:请输入添加人的年级"/>
			   <span style="margin-left: 10px; color: red;">*</span>
		     <div class="tips"> </div>
		   </div>
	   </div>

		<div class="form-group">
			<div class="label">
				<label>添加班级：</label>
			</div>
			<div class="field">
				<input type="text" class="input w50" value="${lists[i].class_name}" name="class_name" id="class_name" data-validate="required:请输入添加人的班级"/>
				<span style="margin-left: 10px; color: red;">*</span>
				<div class="tips"> </div>
			</div>
		</div>
	 <div class="form-group">
	   <div class="label">
	     <label>备注：</label>
	   </div>
	   <div class="field">
	     <input type="text" class="input w50" value="${lists[i].remark}" name="remark" id="remark"  />
	     <div class="tips"> </div>
	   </div>
	 </div>
	 `

                        $('.student-list').html(html);
                    }

                    return;
                }
                if (data.status == 500) {
                    alert("添加失败");
                    window.location.href = "stindx.html";
                    return;
                }
                if (data.status == null) {
                    alert("添加异常");
                    window.location.href = "stindx.html";
                    return;
                }
            },
            error: function (XMLHttpRequest, textStatus) {
                if (textStatus === 'timeout') {
                    alert('請求超時');
                    setTimeout(function () {
                        alert('重新请求');
                    }, 2000);
                }
                alert("系统异常ajax失败");
                 window.location.href="stindx.html";
            }

        })
    })
    function check11() {
        var name = document.getElementById("name").value;
        var password1 = document.getElementById("password1").value;
        var password = document.getElementById("password").value;
        var sno = document.getElementById("sno").value;
        var grade = document.getElementById("grade").value;
        var college_name = document.getElementById("college_name").value;
        var class_name = document.getElementById("class_name").value;
        var remark = document.getElementById("remark").value;
        if(sno == null || sno == ""){
            alert("学号不能为空");
            return;
        }
        if(sno.length !=11){
            alert("学号为11位请输入11位");
            return;
        }
        if(name == null || name == ""){
            alert("名字不能为空");
            return;
        }
        if(password1 == null || password1 == ""){
            alert("请再输入密码");
            return;
        }
        if(password == null || password == ""){
            alert("请输入密码");
            return;
        }
        if(password1 != password ){
            alert("两次密码不一样");
            return;
        }
        if(college_name == null || college_name == ""){
            alert("请选择学院");
            return;
        }
        if(grade == null || grade == ""){
            alert("年级不能为空");
            return;
        }
        if(class_name == null || class_name == ""){
            alert("班级不能为空");
            return;
        }
        if(remark == null || remark == ""){
            alert("选择输入备注");
            return;
        }
        $.ajax({
            type: "POST",
            dataType:"json",
            url: "/workview1/updataStudent",
            data: ({
                sno:sno,
                password:password,
                name:name,
                college_name:college_name,
                grade:grade,
                class_name:class_name,
                remark:remark
            }),
            success: function (data) {
               // console.log(data);
                if (data.status == 401) {
                    alert("熔断开启，系统异常");
                    window.location.href = "login.html";
                    return;
                }
                if (data.status == 200) {
                    alert("修改成功")
                    window.location.href = "stindx.html";
                    return;
                }
                if (data.status == 500) {
                    alert("修改失败");
                    window.location.href = "stindx.html";
                    return;
                }
                if (data.status == null) {
                    alert("异常");
                    window.location.href = "stindx.html";
                    return;
                }
            },
            error: function (XMLHttpRequest, textStatus) {
                if (textStatus === 'timeout') {
                    alert('請求超時');
                    setTimeout(function () {
                        alert('重新请求');
                    }, 2000);
                }
                alert("ajax异常");
                window.location.href = "stindx.html";
            }

        });
    }






</script>
</body>
</html>